/**
 * Create a frame and exec scripts in the it, this fix the *Browser Stoped* bug in IE..
 *
 * @name: execScriptInIframe
 * @author: luoluo
 * @date: 2009-04-20
 * @version: 1.1
 *
 * @param{functionName}: Name of the function to be executed in the iframe.
 * @param{iframe}: Optional, specify the iframe, if not provided, a new iframe will be created.
 * 
 * @sample:
 *
 * function payload() {
 * 	 alert("hello world!");
 * }
 *
 * execScriptInIframe(payload);
 *
 */
function execScriptInIframe(/*functionName, iframe*/) {
	if (/MSIE/.test(window.navigator.userAgent)) {
		if (document.readyState != "loaded" &&
			document.readyState != "complete") {
			var args = arguments;
			
			if (window.onload) {
				var onloadProc = window.onload;
			}
			
			window.onload = function() {
				args.callee.apply(window, args);
				
				if (onloadProc) {
					onloadProc();
				}
			}
			return;
		}
	}

	var functionName = arguments[0];
	var iframe;
	
	if (arguments.length > 1) {
		iframe = arguments[1];
	}
	
	if (! iframe) {
		var pnl = document.createElement("div");
		pnl.style.display = "none";
		
		iframe = document.createElement("iframe");
		iframe.style.display = "none";
		pnl.appendChild(iframe);
		
		document.documentElement.appendChild(iframe);
	}

	var d;
	
	if (iframe.contentWindow) {
		d = iframe.contentWindow.document;
	} else {
		d = iframe.document;	
	}
	
	d.write("<script>\n(" + functionName.toString() + ")();<\/script>");
	d.close();			
}